1 00:00:00,460 --> 00:00:05,950 So I need to add a few things to my pistol, namely a kickback animation. 2 00:00:05,950 --> 00:00:13,240 I need a cooldown and I need a muzzle flash because if we shoot doesn't look like it's doing anything. 3 00:00:13,240 --> 00:00:14,920 Let's go ahead and get started with that. 4 00:00:15,700 --> 00:00:19,060 So my simple pistol is in my starter pack. 5 00:00:19,060 --> 00:00:20,140 We can leave it there. 6 00:00:20,140 --> 00:00:25,270 I'll work on it right from the starter pack and I'm going to save this off because now that it's kind 7 00:00:25,270 --> 00:00:29,050 of working, if I mess it up, I want to be able to get the old one back. 8 00:00:29,050 --> 00:00:34,300 So I'm going to right click, I'm going to hit, let's see, Saved roadblocks. 9 00:00:34,300 --> 00:00:36,880 And then you could put like version one here. 10 00:00:36,880 --> 00:00:38,560 I actually have a version one. 11 00:00:38,560 --> 00:00:44,230 I'm just demoing this, so I'm going to do overwrite an existing asset. 12 00:00:45,180 --> 00:00:47,340 Click that, there's my version one. 13 00:00:47,340 --> 00:00:49,170 I'm just going to overwrite that. 14 00:00:50,070 --> 00:00:51,120 Submit. 15 00:00:51,870 --> 00:00:54,840 But if you don't have one, you can just hit the submit on that first window. 16 00:00:55,560 --> 00:00:56,220 All righty. 17 00:00:56,220 --> 00:01:03,690 Now let's open our simple pistol and hit the plus sign and add a configuration. 18 00:01:03,860 --> 00:01:04,230 Right. 19 00:01:04,230 --> 00:01:05,550 This is actually a folder. 20 00:01:05,550 --> 00:01:09,810 We're going to put stuff on here that we can use to configure our pistol. 21 00:01:09,810 --> 00:01:11,670 We're going to put the damage in there. 22 00:01:11,670 --> 00:01:13,560 We're going to put the cool down. 23 00:01:13,560 --> 00:01:16,050 We're going to put how much ammo we have. 24 00:01:16,050 --> 00:01:19,080 But right now we're just going to work on cool down. 25 00:01:19,080 --> 00:01:23,430 So hit that plus sign and then we're going to add a number value. 26 00:01:24,930 --> 00:01:26,220 There it is. 27 00:01:26,400 --> 00:01:28,070 Let's go ahead and write. 28 00:01:28,080 --> 00:01:29,610 Cool down. 29 00:01:31,680 --> 00:01:36,510 And we'll go down here to the value and make the cool down one second. 30 00:01:36,510 --> 00:01:38,100 But we can make it like 1.5. 31 00:01:38,100 --> 00:01:41,610 That's why I use a number value rather than an int value. 32 00:01:43,520 --> 00:01:43,610 I. 33 00:01:43,610 --> 00:01:45,690 So now let's go to our shoot script. 34 00:01:45,710 --> 00:01:47,070 Open that up. 35 00:01:47,090 --> 00:01:50,750 And I want to get a reference to my configuration folder. 36 00:01:50,970 --> 00:01:51,950 Let's say local. 37 00:01:52,070 --> 00:01:53,390 We'll call it config. 38 00:01:53,540 --> 00:01:56,150 And we have a gun variable here. 39 00:01:56,390 --> 00:01:58,780 Wait for child configuration. 40 00:01:58,790 --> 00:01:59,360 There we go. 41 00:01:59,360 --> 00:02:00,290 We got that. 42 00:02:00,830 --> 00:02:07,760 I'll do another variable for cool down and that's in config. 43 00:02:08,300 --> 00:02:10,530 So let's get our config variable. 44 00:02:10,550 --> 00:02:12,230 We'll do a wait for child. 45 00:02:12,560 --> 00:02:13,640 Cool down. 46 00:02:14,990 --> 00:02:18,790 I need another variable for my D bounce. 47 00:02:18,800 --> 00:02:23,360 So a D bounce is something that prevents software from firing too much. 48 00:02:23,390 --> 00:02:26,890 It's actually used in digital electronics too, but I don't want to get into that. 49 00:02:26,900 --> 00:02:30,170 Let's call this can shoot. 50 00:02:30,770 --> 00:02:33,950 So this is going to prevent us from shooting during the cool down. 51 00:02:33,950 --> 00:02:35,510 It's going to be a boolean. 52 00:02:35,660 --> 00:02:39,770 We'll initialize it to true so we can shoot right away when we get the gun. 53 00:02:39,770 --> 00:02:42,020 But then we got to wait after we fire it. 54 00:02:42,230 --> 00:02:44,760 So I'm going to go down to on activated. 55 00:02:44,780 --> 00:02:47,720 That's where we do our firing when we click on something. 56 00:02:47,900 --> 00:02:50,000 I'm going to do a check. 57 00:02:50,000 --> 00:02:53,570 If can shoot, then I will shoot. 58 00:02:53,570 --> 00:02:59,990 I will send my stuff to the server because the shoot is a client, a client script. 59 00:03:00,410 --> 00:03:00,650 All right. 60 00:03:00,650 --> 00:03:01,940 But that's not sufficient. 61 00:03:01,970 --> 00:03:03,200 It's going to keep shooting. 62 00:03:03,200 --> 00:03:07,420 What we need to do is as soon as we shoot, we're going to set it to false. 63 00:03:07,430 --> 00:03:08,810 We're going to set this to false. 64 00:03:08,810 --> 00:03:12,260 And this statement will not fire until we turn it back. 65 00:03:12,590 --> 00:03:14,780 So I will wait. 66 00:03:14,780 --> 00:03:18,380 After I do my shoot, I'm going to get my cool down. 67 00:03:19,010 --> 00:03:19,550 There it is. 68 00:03:19,580 --> 00:03:21,500 Now, remember, this is an int value. 69 00:03:21,500 --> 00:03:24,980 So we have to do the value or a number of values. 70 00:03:24,980 --> 00:03:25,730 A number of value. 71 00:03:25,760 --> 00:03:31,430 We still have to do the value and then I'll do a can shoot equals after we wait. 72 00:03:31,610 --> 00:03:32,280 True. 73 00:03:32,300 --> 00:03:38,360 So we will shoot because this is true when we first start out, then becomes false. 74 00:03:38,600 --> 00:03:42,550 We fire to the server that does the bang and the damage. 75 00:03:42,560 --> 00:03:48,990 Then we wait for our cool down and we can't shoot again until we get past our cool down. 76 00:03:49,010 --> 00:03:50,340 That's pretty cool. 77 00:03:50,360 --> 00:03:51,980 Let's go ahead and try it out. 78 00:03:57,260 --> 00:03:58,760 Or we're in our world. 79 00:03:58,790 --> 00:04:02,780 Pull out the pistol and I'm spamming 80 00:04:05,090 --> 00:04:09,020 and spamming the click so you can see that it shoots about once a second, right? 81 00:04:09,020 --> 00:04:10,270 That's the cooldown. 82 00:04:10,280 --> 00:04:17,300 Now I'm going to do one more thing for the purist, because sometimes people say, Well, the shoot 83 00:04:17,300 --> 00:04:23,780 script is a local script, which means it can be modified on the client, and if somebody really knows 84 00:04:23,780 --> 00:04:26,360 what they're doing, then they can make their game more powerful. 85 00:04:26,360 --> 00:04:32,540 So if you really want to be careful, let's go ahead and copy these. 86 00:04:34,440 --> 00:04:37,170 Now go and open up your damaged script. 87 00:04:38,170 --> 00:04:41,320 And we're going to paste the same variables. 88 00:04:41,860 --> 00:04:42,580 There we go. 89 00:04:42,580 --> 00:04:47,440 And this we don't have gun on this side, so I need to do a script parent. 90 00:04:49,600 --> 00:04:53,300 And we've got our configuration, our cool down and can shoot. 91 00:04:53,320 --> 00:04:56,770 Now let's go down to on shoot. 92 00:04:58,510 --> 00:05:00,090 Now we'll do an if statement. 93 00:05:00,100 --> 00:05:05,320 If I can shoot then. 94 00:05:06,100 --> 00:05:09,880 You know, bring this down here to the bottom and. 95 00:05:10,640 --> 00:05:11,690 I need to format. 96 00:05:12,750 --> 00:05:13,650 Cool. 97 00:05:14,040 --> 00:05:17,070 Can shoot will become false as soon as we shoot. 98 00:05:18,330 --> 00:05:22,140 And then we'll go down to the bottom after we do the shooting. 99 00:05:23,320 --> 00:05:23,920 Yes. 100 00:05:23,920 --> 00:05:28,510 Right here gets a little tricky when you get a lot of ifs and ends. 101 00:05:28,690 --> 00:05:30,760 We'll do our weight, right? 102 00:05:30,760 --> 00:05:31,150 Weight. 103 00:05:31,150 --> 00:05:32,740 We have our cool down. 104 00:05:33,220 --> 00:05:35,690 And cool down is a number value. 105 00:05:35,710 --> 00:05:40,600 I guarantee you you're going to forget this at least a couple of times in your programming. 106 00:05:40,840 --> 00:05:42,040 We all do. 107 00:05:42,070 --> 00:05:43,690 You get used to it, though. 108 00:05:44,080 --> 00:05:49,150 And then after we weight can shoot will be true. 109 00:05:49,540 --> 00:05:52,600 So essentially, we're doing the exact same thing on the server side. 110 00:05:52,600 --> 00:05:54,740 The remote event is going to fire. 111 00:05:54,760 --> 00:05:59,020 There might be like a little millisecond delay, but it's going to be pretty quick. 112 00:05:59,320 --> 00:06:04,900 Remote events are asynchronous calls, so the lineup's not going to be perfect, but better than what 113 00:06:04,900 --> 00:06:06,750 a user can can tell. 114 00:06:06,760 --> 00:06:09,480 So you're just adding some strength here. 115 00:06:09,490 --> 00:06:14,770 If you didn't have this code, you wouldn't notice unless someone tried to hack your hack your game. 116 00:06:14,920 --> 00:06:16,300 All right, So now let's try it. 117 00:06:16,300 --> 00:06:17,620 Make sure everything's good. 118 00:06:20,640 --> 00:06:21,320 I think. 119 00:06:21,360 --> 00:06:24,330 Let's look at our view output. 120 00:06:24,900 --> 00:06:26,750 Yeah, no problem. 121 00:06:26,760 --> 00:06:33,990 Now, all the other configuration stuff like damage and ammo, we're going to only be server side, 122 00:06:33,990 --> 00:06:39,030 but we needed to have the DH balance for the cooldown on the client side because now we're going to 123 00:06:39,030 --> 00:06:41,190 add a kickback animation.